#ifndef __LIB_AGORA_CLIENT_CLIENT_H__
#define __LIB_AGORA_CLIENT_CLIENT_H__

#include "Connection.h"
#include "IBuffer.h"
#include "ThreadPool.h"
#include "IEmpacter.h"
#include "Guest.h"
#include "IMutex.h"
#include "IBuffer.h"
#include "IEvent.h"

using namespace AgoraCore;

namespace AgoraClient
{

class Client
{
public:
	Client(IBuffer *bufferSound, IBuffer *bufferTxtAdm, unsigned int bufferReadSize);
	~Client();
	int				Disconnect();
	int				GetId();
	int				Connect(const std::string& adress, int portTxtAdm, int portSound, const std::string& login, const std::string& pass);
	bool			IsConnected();

	unsigned int			SendBufferSound(void* data, unsigned int size);
	unsigned int			SendBufferTxtAdm(void* data, unsigned int size);
	

private:
	static void				SendDataSound(void* client);
	static void				SendDataTxtAdm(void* client);
	enum ReceiveState
	{
		HEADER,
		PACKET
	};
	IBuffer*		_bufferSound;
	IBuffer*		_bufferTxtAdm;
	unsigned int	_bufferReadSize;
	int				_id;
	unsigned int	_availableToSendSound;
	unsigned int	_availableToSendTxtAdm;
	bool			_sendLoop;
	bool			_isConnected;
	Guest* _connectionTxtAdm;
	Guest* _connectionSound;
	static void		SelectReceiveTxtAdm(void* client);
	static void		SelectReceiveSound(void* client);
	static void		SelectReceive(Guest* connection, IBuffer *buffer, unsigned int bufferReadSize, unsigned int len, unsigned int available, char *buff);
	int				Authentificate(const std::string& login, const std::string& pass);


	IBuffer*				_buffSendSound;
	IMutex*					_lockSendSound;
	IBuffer*				_buffSendTxtAdm;
	IMutex*					_lockSendTxtAdm;
	IEvent*					_eventBufferSound;
	IEvent*					_eventDestructorSound;
	IEvent*					_eventBufferTxtAdm;
	IEvent*					_eventDestructorTxtAdm;
};

}

#endif
